﻿using AutoMapper;
using MediatR;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command;

namespace U.B.WriteApi.CommandHander
{
    public class UpdateMenuCommandHander : IRequestHandler<UpdateMenuCommand, ApiResult<object>>
    {
        public readonly IRepistory<Menu>_menuRepository;
        public readonly IMapper _mapper;
        public UpdateMenuCommandHander(IRepistory<Menu> menuRepository, IMapper mapper)
        {
            _menuRepository = menuRepository;
            _mapper = mapper;
        }
        /// <summary>
        /// 菜单修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<object>> Handle(UpdateMenuCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> result = new ApiResult<object>();
            var result1= _mapper.Map<Menu>(request);
             _menuRepository.Update(result1);
            result.code = Renum.修改成功;
            result.Message=Renum.修改成功.ToString();
            return Task.FromResult(result);
        }
    }
}
